<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3" xmlns:head="http://www.w3.org/1999/html">
<head th:include="public/public_css::public_css ('订单量汇总报表')" />

<body style="background-color: #f2f2f2;">
<div class="layui-fluid larry-wrapper">
    <div class="layui-card">
        <div class="layui-row layui-col-space30">
            <div class="layui-col-xs24">
                <form class="layui-form layui-card-header  layui-card-header-auto" id="searchForm">
                    <input type="hidden" id="cjsj_start" name="cjsj_start">
                    <div class="layui-inline">
                        <label class="layui-form-label">产品类别</label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" id="cplb" name="cplb" placeholder="请输入产品类别" />
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">查询时间</label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" id="cjsj" placeholder="请选择时间范围" />
                        </div>
                    </div>
                    <div class="layui-inline inline-search-btn">
                        <a class="layui-btn layui-btn-normal search_btn" lay-event="searchEvent" data-type="reload">查询</a>
                    </div>
                    <div class="layui-inline inline-reset-btn">
                        <button id="chongzhi" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </form>
                <!--顶部按钮展示区域 【 tpl-button 】 -->
                <div class="group-button tpl-button" id="toolbar"></div>
                <!--列表-->
                <section class="panel panel-padding layui-card-body">
                    <div class="pro">
                        <table id="table" class="table text-nowrap"></table>
                    </div>
                </section>
            </div>
        </div>
    </div>
</div>
</body>

<div th:include="public/public_js::public_js"></div>
<div th:include="public/public_btn::public_btn"></div>
<script th:inline="javascript">
    var dates;
    var functions = [[${functions}]];
    var ids=[];
    layui.use(['list','layer','zzpUtils','jquery','laydate','tablebutton'],function () {

        var zzpUtils= layui.zzpUtils,
            $ = layui.jquery,
            laydate = layui.laydate,
            tablebtn = layui.tablebutton;
        var $table;

        tablebtn.buildOnClick({
            type: 1,
            temp: $("#function_tpl"),
            functions: functions.headBtn,
            row: null,
            event: {
                searchEvent: function(){
                    zzpUtils.refreshTable("#table");
                },
                /*导出*/
                exportEvent: function (data) {
                    var arr = [];
                    var $rows = $table.bootstrapTable('getSelections');
                    if (ids.length > 0) {
                        arr = $.map(ids, function (id) {
                            return id;
                        })
                    }
                    /*
                     * 以下是将ids和对象拼接在一起
                     * */
                    var str = zzpUtils.getFormJson($("#searchForm"));
                    var object2 = Object.assign({ids: arr}, str);
                    /*将条件查询和ids传到后台*/
                    zzpUtils.outputXslx({
                        url: "/wmsclassify/outClassify",
                        data: JSON.stringify(object2)
                    });
                }

            }
        });
        //初始化
        zzpUtils.webSocket.init();
        var myDate = new Date();
        var years=myDate.getFullYear(); //获取完整的年份(4位,1970-????)
        var mouths=myDate.getMonth(); //获取当前月份(0-11,0代表1月)
        if(myDate.getMonth()==0){
            years=years-1;
        }
        if(myDate.getMonth()<10){
            mouths="0"+mouths;
        }

        var mytime=myDate.toLocaleTimeString(); //获取当前时间
        myDate.toLocaleString( ); //获取日期与时间
        dates=years+"-"+mouths;
        $("#cjsj_start").val(dates);
        //创建时间转换时间戳
        laydate.render({
            elem: '#cjsj',
            type: 'month',
            value: dates,
            /*range: '~',*/
            done: function(value, date, endDate){
                if(value!=null && value!=""){
                    console.log(1111111111)
                    $("#cjsj_start").val(value);
                }else {
                    $("#cjsj_start").val("");
                }

                console.log(value); //得到日期生成的值，如：2017-08-18
                console.log(date); //得到日期时间对象：{year: 2017, month: 8, date: 18, hours: 0, minutes: 0, seconds: 0}
                console.log(endDate); //得结束的日期时间对象，开启范围选择（range: true）才会返回。对象成员同上。
            }
        });
        //查询list
        var $table = zzpUtils.table({
            elem: '#table',
            isApi: true,
            pagination: true,
            autoWidth: false,
            scrollX: true,
            url: '/wmsclassify/baseHarvestPage',
            columns: [{
                field: '',
                checkbox: true,
                // 显示复选框
                formatter: function (i,row) {
                    // 每次加载 checkbox 时判断当前 row 的 id 是否已经存在全局 Set() 里
                    if ($.inArray(row.id, ids) != -1) {// 因为 判断数组里有没有这个 id
                        return {
                            checked: true               // 存在则选中
                        }
                    }

                }
            }, {
                field: 'cplb',
                title: '产品类别'
            },{
                field: 'ydl',
                title: '运单量'
            },{
                field: 'ddl',
                title: '订单量'
            },{
                field: 'xs',
                title: '箱数'
            },{
                field: 'zs',
                title: '支数'
            },{
                field: 'xse',
                title: '销售额'
            },{
                field: 'yf',
                title: '运费'
            },{
                field: 'yfxse',
                title: '运费/销售额'
            },{
                field: 'cjsj',
                title: '创建时间',
                sortable: true,
                //——修改——获取日期列的值进行转换
                formatter: function (value, row, index) {
                    return changeDateFormat(value)
                }
            }
            ],
            queryParams: function () {//查询条件
                return  zzpUtils.getFormJson($("#searchForm"));
            },
            detailFormatter: function (index, row) {
                return "这里就没有确定过11";
            },onCheck: function (row) {
                btn_cha(row.id);
            },
            onUncheck: function (row) {
                btn_cha(row.id);
            },
            onCheckAll: function (rows) {
                $.each(rows, function (i, item) {
                    btn_cha(item.id);
                });

            },
            onUncheckAll: function (rows) {
                $.each(rows, function (i, item) {
                    btn_cha(item.id);
                });
            }
        });

        $('#chongzhi').click(function () {
            $('#cjsj').val(dates);
            $('#cplb').val("");
            $('#table').bootstrapTable('refresh', {cjsj_start: dates, cplb: '', page: 1, rows: 10});
        })
    });
    //修改——转换日期格式(时间戳转换为datetime格式)
    function changeDateFormat(cellval) {
        if (cellval != null) {
            return cellval.substr(0,19);
        }
    }
    function btn_cha(id){
        if(ids.indexOf(id)>-1){
            var index = ids.indexOf(id);
            if (index > -1) {
                ids.splice(index, 1);
            }
        }else{
            ids.push(id);
        }
    }

</script>
</html>